package com.hmdp.asserts;

import com.hmdp.exception.BaseException;
import com.hmdp.exception.BusinessException;


/**
 * date: 2023/9/9 10:56
 * author: MR.孙
 */
public enum Asserts implements IAssert{

    // 通用状态码
    NOT_FOUND(404, "找不到请求的资源"),

    // 自定义状态码
    // 成功 状态码区间 200 - 299
    SUCCESS(200, "操作成功"),

    // 失败 状态码区间 500 - 599
    FAILURE(500, "出现错误"),
    IS_NULL(501, "出现空值")
    ;

    public  int code;

    public  String msg;

    Asserts(int code, String msg) {
        this.msg = msg;
        this.code = code;
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    /**
     * 业务异常
     * @param msg
     * @return
     */
    @Override
    public BaseException newException(String msg) {
        return new BusinessException(msg, this);
    }

    /**
     * 业务异常
     * @return
     */
    @Override
    public BaseException newException() {
        return newException(msg);
    }


}
